package com.zonski.jbots.engine.entity;

public final class Trig
{
    private static final int[] XMULTS = 
    {
        0,  // NONE
        0,  // NORTH
        2,  // NORTH_EAST
        1,  // EAST
        2,  // SOUTH_EAST
        0,  // SOUTH
        -2, // SOUTH_WEST
        -1, // WEST
        -2, // NORTH_WEST
    };
    private static final int[] XDIVS = 
    {
        1,  // NONE
        1,  // NORTH
        3,  // NORTH_EAST
        1,  // EAST
        3,  // SOUTH_EAST
        1,  // SOUTH
        3,  // SOUTH_WEST
        1,  // WEST
        3,  // NORTH_WEST
    };

    private static final int[] YMULTS = 
    {
        0,  // NONE
        1,  // NORTH
        2,  // NORTH_EAST
        0,  // EAST
        -2, // SOUTH_EAST
        -1, // SOUTH
        -2, // SOUTH_WEST
        0,  // WEST
        2,  // NORTH_WEST
    };
    private static final int[] YDIVS = 
    {
        1,  // NONE
        1,  // NORTH
        3,  // NORTH_EAST
        1,  // EAST
        3,  // SOUTH_EAST
        1,  // SOUTH
        3,  // SOUTH_WEST
        1,  // WEST
        3,  // NORTH_WEST
    };

    private static final int[][] MULTS =
    {
        XMULTS, YMULTS
    };

    private static final int[][] DIVS = 
    {
        XDIVS, YDIVS
    };

    public static final int X_INDEX = 0;
    public static final int Y_INDEX = 1;

    public static int getUnitVelocity(int velocity, int direction, 
            int unitIndex, int modIndex)
    {
        int mult = MULTS[unitIndex][direction];
        int div = DIVS[unitIndex][direction];
        int mod = Math.abs(mult)%div;
        int add;
        if(modIndex%div < mod && (velocity != 0))
        {
            if(mult > 0)
            {
                add = 1;
            }else if(mult < 0){
                add = -1;
            }else{
                add = 0;
            }
        }else{
            add = 0;
        }
        return ((velocity * mult)/div) + add;
    }
    
    private Trig()
    {
    }
}
